/*******************************************************************************
 * @project: ServletTest
 * @package: com.burns.servlet.cookie
 * @file: DeleteCookies.java
 * @author: Administrator
 * @created: 2017年5月18日
 * @purpose:
 * 
 * @version: 1.0
 * 
 * Revision History at the end of file.
 * 
 * Copyright 2017 AcconSys All rights reserved.
 ******************************************************************************/

package com.burns.servlet.cookie;

//导入必需的 java 库
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

//扩展 HttpServlet 类
public class DeleteCookies extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Cookie cookie = null;
		Cookie[] cookies = null;
		// 获取与该域相关的 Cookies 的数组
		cookies = request.getCookies();

		response.setCharacterEncoding("utf-8");
		// 设置响应内容类型
		response.setContentType("text/html");

		PrintWriter out = response.getWriter();
		String title = "Delete Cookies Example";
		String docType = "<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
		out.println(
				docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" + "<body bgcolor=\"#f0f0f0\">\n");
		if (cookies != null) {
			out.println("<h2>Cookies 名称和值</h2>");
			for (int i = 0; i < cookies.length; i++) {
				cookie = cookies[i];
				if ((cookie.getName()).compareTo("first_name") == 0) {
					cookie.setMaxAge(0);
					response.addCookie(cookie);
					out.print("已删除的 cookie：" + cookie.getName() + "<br/>");
				}
				out.print("名称：" + cookie.getName() + "，");
				out.print("值：" + cookie.getValue() + " <br/>");
			}
		} else {
			out.println("<h2 class='tutheader'>No cookies founds</h2>");
		}
		out.println("</body>");
		out.println("</html>");
	}
}

/*******************************************************************************
 * <B>Revision History</B><BR>
 * [type 'revision' and press Alt + / to insert revision block]<BR>
 * 
 * 
 * 
 * Copyright 2017 AcconSys All rights reserved.
 ******************************************************************************/